export const formatNumber = (value: any, digits: number = 1): string => {
  const num = Number(value);
  return isNaN(num) ? '0.0' : num.toFixed(digits);
};

export const formatPercentage = (numerator: any, denominator: any): string => {
  const num = Number(numerator);
  const den = Number(denominator);
  if (isNaN(num) || isNaN(den) || den === 0) return '0.0';
  return ((num / den) * 100).toFixed(1);
};

export const formatCurrency = (value: any): string => {
  const num = Number(value);
  return isNaN(num) ? '¥0.00' : `¥${num.toLocaleString('zh-CN', { minimumFractionDigits: 2 })}`;
};

export const formatDate = (date: string | Date): string => {
  return new Date(date).toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    weekday: 'long'
  });
};

export const formatTime = (date: string | Date): string => {
  return new Date(date).toLocaleTimeString('zh-CN', {
    hour: '2-digit',
    minute: '2-digit'
  });
};